﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RabbitMQ.Client;
using RabiitMq.Server;

namespace RabiitMq
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello, World!");
            IConnectionFactory factory = new ConnectionFactory//创建连接工厂对象
            {
                HostName = "192.168.60.129",//IP地址
                VirtualHost = "/",
                Port = 5672,//端口号
                RequestedHeartbeat = TimeSpan.FromSeconds(3), // 心跳超时时间（秒）
                NetworkRecoveryInterval = TimeSpan.FromSeconds(3),  //客户端在重新尝试恢复连接之前等待的时间。 等待时间倍数 
                RequestedConnectionTimeout = TimeSpan.FromSeconds(2), //连接尝试的超时设置。 
                AutomaticRecoveryEnabled = true,  //设置为false表示禁用自动连接恢复。
                TopologyRecoveryEnabled = true,//支持异步发送消息
                //DispatchConsumersAsync = true,
                UserName = "admin",//用户账号
                Password = "123456"//用户密码
            };
            IConnection con = factory.CreateConnection();//创建连接对象
            HostApplicationBuilder hostApplicationBuilder = Host.CreateApplicationBuilder(args);
            hostApplicationBuilder.Services.AddSingleton(con);
            hostApplicationBuilder.Services.AddHostedService<RabbitMqHostServer>();
            hostApplicationBuilder.Services.AddHostedService<TwoRabbitMqHostServer>();
            IHost host = hostApplicationBuilder.Build();
            host.Run();
        }
    }
}
